home *** CD-ROM | disk | FTP | other *** search
- /******************************* IPXCHAT ********************************/
- /* This example program will chat between two stations sending a single */
- /* character at a time in either direction. */
- /************************************************************************/
-
- #define ESCAPE_KEY 0x1b
- #define RETURN_KEY 0x0d
-
- #define SHORT_LIVED 0x00
- #define SOCKET 0x4848 /* Socket number we will use */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <dos.h>
- #include <conio.h>
- #include <memory.h>
-
- #include "netware.h"
-
- word program_socket ;
- word server_socket ;
-
- EVENT_CONTROL_BLOCK receiveECB ;
- EVENT_CONTROL_BLOCK sendECB ;
- IPX_HEADER IPX_receive_header ;
- IPX_HEADER IPX_send_header ;
-
- char packet_data;
-
- word connection_number;
-
- /********************** function prototypes ********************/
-
- word SetupForReceive( void );
- void SetupForSend( int connection_number );
- void TransmitReceive( void );
-
- /***************************** main() *************************/
-
- void main( int argc, char *argv[] )
- {
- int rc;
-
- if (argc != 2)
- {
- printf("Invalid number of paramaters\n");
- printf("Usage is:\n");
- printf(" ipxchat <connection_number>\n");
- exit(255);
- }
- else
- connection_number = atoi(argv[1]);
-
- if (IPXInitialise() != 0)
- {
- printf("IPX is not installed........\n");
- exit(255);
- }
- else
- printf("IPX Initialised.......\n");
- program_socket = SOCKET;
- if (IPXOpenSocket( &program_socket , SHORT_LIVED ) != 0)
- {
- printf("Failed to open socket %04.4X\n",SOCKET);
- exit(255);
- }
- else
- printf("Socket %04.4X opened\n",SOCKET);
- if ( (rc = SetupForReceive()) != 0)
- printf("Failed to create listen ECB: %d\n",rc);
- else
- {
- printf("Receive ECB created\n");
- SetupForSend(connection_number) ;
- TransmitReceive() ;
- }
- IPXCloseSocket(program_socket) ;
- }
-
- /********************** SetupForReceive ***********************/
- word SetupForReceive( void )
- {
- memset( (void *)&receiveECB,0,sizeof(EVENT_CONTROL_BLOCK));
-
- NWintconvert( program_socket, &(receiveECB.socket_number) );
-
- receiveECB.fragment_count = 2 ;
- receiveECB.esr = (void (_far *) () ) 0 ;
-
- receiveECB.fragment[0].address = (void *)&IPX_receive_header;
- receiveECB.fragment[0].length = sizeof(IPX_receive_header);
-
- receiveECB.fragment[1].address = (void *)&packet_data;
- receiveECB.fragment[1].length = 1;
-
- return( IPXListenForPacket( &receiveECB ) );
- }
-
- /*********************** SetupForSend *************************/
- void SetupForSend( int connection_number )
- {
- word transport_time;
-
- GetInternetAddress( connection_number,
- IPX_send_header.dest_addr.ina.network_number,
- IPX_send_header.dest_addr.ina.node_address,
- &server_socket);
- IPX_send_header.packet_type = 4 ;
- NWintconvert(program_socket,&IPX_send_header.dest_addr.socket_number);
-
- memset( (void *)&sendECB,0,sizeof(EVENT_CONTROL_BLOCK));
-
- IPXGetLocalTarget(&IPX_send_header.dest_addr.ina,
- sendECB.immediate_address,&transport_time);
- NWintconvert( program_socket, &(sendECB.socket_number) );
-
- sendECB.fragment_count = 2;
- sendECB.esr = (void (far *) () ) 0 ;
-
- sendECB.fragment[0].address = (void *)&IPX_send_header;
- sendECB.fragment[0].length = sizeof(IPX_send_header);
-
- sendECB.fragment[1].address = (void *)&packet_data;
- sendECB.fragment[1].length = 1;
- }
-
- /******************** TransmitReceive ************************/
- void TransmitReceive( void )
- {
- int done;
-
- system("cls") ;
- printf("Enter character to give to other side.\n");
- printf("(Type ESCAPE to exit.)\n");
-
- done = 0;
-
- while(!done)
- {
- IPXRelinquishControl();
-
- if (!receiveECB.in_use)
- {
- switch(packet_data)
- {
- case RETURN_KEY :
- printf("\n");
- break;
- case ESCAPE_KEY :
- done = 1;
- break;
- default :
- printf("%c", packet_data);
- break;
- }
- IPXListenForPacket( &receiveECB );
- }
- if (kbhit())
- {
- while(sendECB.in_use);
- packet_data = (char) getch();
- switch(packet_data)
- {
- case RETURN_KEY : printf("\n");
- break;
- case ESCAPE_KEY :
- done = 1;
- break;
- default :
- printf("%c", packet_data);
- break;
- }
- IPXSendPacket( &sendECB );
- }
- }
-
- IPXCancelEvent( &receiveECB );
- }
-